package repository

import (
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"sync"
	"traning/db_pool_application/mongodb"
)

var instance *taskRepository
var once sync.Once

type taskRepository struct {
	mongoClient *mongodb.Mongodb
}

func GetTaskRepositoryInstance() *taskRepository {
	once.Do(func() {
		instance = new(taskRepository)
		instance.mongoClient = mongodb.GetMongodbInstance()
	})
	return instance
}

func (this *taskRepository) QueryQuotation (collection string, condition string) ([]map[string]interface{}, error) {
	return this.mongoClient.Query(collection, bson.M{"componentType":condition})
}

func (this *taskRepository) QueryById (collection string, condition primitive.ObjectID) ([]map[string]interface{}, error) {
	return this.mongoClient.Query(collection, bson.M{"_id":condition})
}